<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../js/jquery-1.8.3.js"></script>
</head>

<body>
    <input type="button" class="pox" value="0.01">
    <input type="button" class="pox" value="0.02">
    <input type="button" class="pox" value="0.03">
    <input type="text" class="poy" value="111">
    <input type="text" class="poy" value="222">
    <input type="text" class="poy" value="333">
    <script>
        //测试JavaScript闭包
        var a = document.getElementsByClassName("pox");
        var b = document.getElementsByClassName("poy");
        for (var i = 0; i < 3; i++) {
            //var cvalue = b[i].value;
            (function(i){
                $(a[i]).on("click",function () {
                    $.ajax({
                        type: "GET",
                        dataType: "JSON",
                        url: "http://localhost:8080/handleValue?value=" + b[i].value,
                        success: function (obj) {
                            console.log("请求成功! " + JSON.stringify(obj));
                        },
                        error: function (err) {
                            console.log("出现错误! " + err.message);
                        }
                    });
                });
            })(i);
        }
    </script>
</body>

</html>